import java.util.Scanner;

public class Solution {
    public int minOperations(int[] nums, int x){
        int sum = 0,len = nums.length;
        for (int i = 0; i < len; i++) {
            sum += nums[i];
        }
        int target = sum - x;

        if(target < 0) return -1;

        int ret = -1;
        for (int left = 0,right = 0,tmp = 0;right < len;right++){
            tmp += nums[right];//进窗口
            while(tmp > target)//判断
                tmp -= nums[left++];//出窗口
            if(tmp == target)
                ret = Math.max(ret,right - left + 1);//更新结果
        }
        if(ret == -1) return ret;
        else return len - ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = in.nextInt();
            }
            int x = in.nextInt();
            Solution solution = new Solution();
            System.out.println(solution.minOperations(arr, x));
        }
    }
}
